package lengthOfLongestSubstring;

import java.util.HashMap;

public class Solution3 {
    int maxLen = 0;
    public int lengthOfLongestSubstring(String s){
        if (s.length() == 0)
            return 0;
        if (s.equals(" "))
            return 1;
        int start = 0;
        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        while (start < s.length()){
            if (map.containsKey(s.charAt(start))){
                maxLen = Math.max(maxLen, map.size());
                start = map.get(s.charAt(start)) + 1;
                map.clear();
            } else {
                map.put(s.charAt(start), start);
                start++;
                maxLen = Math.max(maxLen, map.size());
            }
        }
        return maxLen;
    }
}
